package com.qf.day12;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Random;

public class PukeCardUtils {
    // 声明扑克点数的数组
    public static final String[] POINTS_ARR = {"3","4","5","6","7","8","9","10","J","Q","K","A","2","SJOKER","BJOKER"};

    // 声明扑克花色的数组
    public static final String[] PUKE_TYPE = {"♥","♠","♦","♣"};


    /**
     * 模拟斗地主抓牌
     * @param cards  54张牌
     * @param p1  玩家1的手牌
     * @param p2
     * @param p3
     * @param d1  底牌，剩三张
     */
    public static void drawPukeCard(List<PukeCard> cards, List<PukeCard> p1, List<PukeCard> p2,
                                    List<PukeCard> p3, List<PukeCard> d1){
        //每名玩家17张牌，留三张底牌
        int eachPlayerCards = 17;
        int bottomCards = 3;
        int totalCards = cards.size();

        if (cards == null || p1 == null || p2 == null || p3 == null || d1 == null ||
                cards.size() != 54 || // 一副牌（不包括大小王）共54张
                p1.size() != 0 || p2.size() != 0 || p3.size() != 0 || d1.size() != 0) {
            throw new IllegalArgumentException("Invalid parameters for drawing cards");
        }

        // 为每个玩家抓取牌
        for (int i = 0; i < eachPlayerCards; i++) {
            p1.add(cards.remove(0));
            p2.add(cards.remove(0));
            p3.add(cards.remove(0));
        }

        // 留下底牌
        for (int i = 0; i < bottomCards; i++) {
            d1.add(cards.remove(0));
        }

    }
    public static void shuffle(List<PukeCard> cards) {
        Collections.shuffle(cards, new Random());
    }

    /**
     * 创建一副扑克牌
     * @return
     */
    public static List<PukeCard> createPukeList(){

        ArrayList<PukeCard> pukeCards = new ArrayList<>();

        for (int i = 0; i < POINTS_ARR.length-2; i++) {
            for (String type : PUKE_TYPE) {
                PukeCard pukeCard = new PukeCard(type, POINTS_ARR[i], i);
                pukeCards.add(pukeCard);
            }
        }
        // 单独处理大小王
        PukeCard sjoker = new PukeCard("", "SJOKER", 13);
        PukeCard bjoker = new PukeCard("", "BJOKER", 14);
        pukeCards.add(sjoker);
        pukeCards.add(bjoker);


        return pukeCards;
    }

    public static void main(String[] args) {
        List<PukeCard> pukeList = createPukeList();
        for (PukeCard pukeCard : pukeList) {
            System.out.println(pukeCard);
        }
        System.out.println(pukeList.size());

        ArrayList<PukeCard> p1 = new ArrayList<>();
        ArrayList<PukeCard> p2 = new ArrayList<>();
        ArrayList<PukeCard> p3 = new ArrayList<>();
        ArrayList<PukeCard> d1 = new ArrayList<>();

        drawPukeCard(pukeList,p1,p2,p3,d1);

        System.out.println("玩家1"+p1);
        System.out.println("玩家2"+p2);
        System.out.println("玩家3"+p3);
        System.out.println("底牌"+d1);

    }

}
